<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<link rel="stylesheet" type="text/css" href="../../../Themes/default/easyui.css">
		<link rel="stylesheet" type="text/css" href="../../../Themes/icon.css">
		<link rel="stylesheet" type="text/css" href="../../../CSS/demo.css">
		<link rel="stylesheet" type="text/css" href="../../../CSS/common.css">
		<link rel="stylesheet" type="text/css" href="../../../CSS/print.css">
		<style>
			#star {
				color: red;
			}
		</style>
	</head>

	<body style="padding: 0px;">

		<div id="toolbar" style="background: #F4F4F4;border-top:1px solid #95B8E7">
		</div>
		<div style="float: right;margin-top: 0px;max-width:60px;" id="notreview"></div>
		<div>
			<form id="ff" action="#" method="post">
				<table cellpadding="5" class="displaytable" style="text-align: left;width: 80%;margin: 0 auto;">
					<tr>
						<td width="10%">
							<h id="star">* </h>配送时间</td>
						<td width="25%">
							<input type="text" id="input_DISTRIBUTION_DATE" class="easyui-datebox" name="DISTRIBUTION_DATE" data-options="prompt:'请输入配送时间',required:'true'" />
						</td>
						<td width="10%">
							<h id="star">* </h>配送员</td>
						<td width="25%">
							<input type="text" id="input_DELIVERY_MAN" class="easyui-textbox" name="DELIVERY_MAN" data-options="prompt:'请输入配送员名称',required:'true'" />
						</td>
						<td width="10%">
							<h id="star">* </h>配送方式</td>
						<td width="25%">
							<input type="combobox" id="input_DELIVERY_METHOD" class="easyui-combobox" name="DELIVERY_METHOD" data-options="prompt:'请输入配送方式',required:'true'" />
							<a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-add'" onclick="AddDELIVERY_METHODName()"></a>
						</td>
					</tr>
					<tr>

						<td>
							<h id="star">* </h>车牌号</td>
						<td>
							<input type="text" id="input_CAR_NO" class="easyui-textbox" name="CAR_NO" data-options="prompt:'请输入配送车辆车牌号',required:'true'" />
						</td>
						<td>
							<h id="star">* </h>租车费用</td>
						<td>
							<input type="text" id="input_RENT_COST" class="easyui-numberbox" name="RENT_COST" precision="2" />
						</td>
						<td>
							<h id="star">* </h>装卸费用</td>
						<td>
							<input type="text" id="input_HANDING_COST" class="easyui-numberbox" name="HANDING_COST" precision="2" />
						</td>
					</tr>
					<tr>
						<td>
							<h id="star">* </h>油费</td>
						<td>
							<input type="text" id="input_OIL_COST" class="easyui-numberbox" name="OIL_COST" precision="2" />
						</td>
						<td>
							<h id="star">* </h>其他费用</td>
						<td>
							<input type="text" id="input_OTHER_COST" class="easyui-numberbox" name="OTHER_COST" precision="2" />
						</td>
						<td>
							<h id="star">* </h>费用总计</td>
						<td>
							<input type="text" id="input_LUMP_SUM" class="easyui-numberbox" name="LUMP_SUM" precision="2" data-options="disabled:true" />
						</td>
					</tr>
					<tr id="nodisplay" style="display: none">
						<td>
							配送单ID</td>
						<td>
							<input type="text" id="input_ID" class="easyui-textbox" name="ID" data-options="disabled:true" />
						</td>
						<td>
							配送单编号</td>
						<td>
							<input type="text" id="input_ORDER_NO" class="easyui-textbox" name="ORDER_NO" data-options="disabled:true" />
						</td>
					</tr>

				</table>
				<div id="tt"></div>
				<div style="margin-left: 20%;" id="new_footer">

				</div>
			</form>
		</div>
		<div id="dlg" class="hiddenDialog">
			<iframe id="ifrmEdit" style="width: 100%;height: 100%;" frameborder="0" scrolling="no"></iframe>
		</div>
		<div id="toolbar2"></div>
	</body>
	<script type="text/javascript" src="../../../JS/jquery.min.js"></script>
	<script type="text/javascript" src="../../../JS/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="../../../JS/common.js"></script>
	<script type="text/javascript" src="../../../JS/finance.js"></script>
	<script type="text/javascript" src="../../../JS/SHA-1.js"></script>
	<script type="text/javascript" src="../../../JS/LogisticsShareFunction/CommonShareFunction.js"></script>
	<script type="text/javascript" src="../../../JS/LogisticsShareFunction/DeliverShareFunction.js"></script>
	<script type="text/javascript">
		var currPage = getID();
		var currid = AddFlag;//当前页面的id
		var updateData;
		var updateLog = "";
		var MaxPage = 0;
		var MinPage = 0;
		var _detailToolbarData;
		var auth = "admin;" + hex_sha1("admin1");
		_detailToolbarData = AddDetailToolBar(7);
		var isVerify;
		///增加脚注
		addFooter($("#new_footer"));
		iniDeliverMethod();
		//增加单据的toolbar
		var receipts_type = RECEIPT_FRONT_SYMBOL;
		receipts_type += RECEIPT_NEXT_SYMBOL + RECEIPT_UNVERIFY_SYMBOL;
		receipts_type += RECEIPT_SAVE_SYMBOL + RECEIPT_DELETE_SYMBOL;
		receipts_type += RECEIPT_PRINT_SYMBOL + RECEIPT_VERIFY_SYMBOL;
		receipts_type += RECEIPT_SEARCH_SYMBOL;
		receipts_type += RECEIPT_EXPORT_SYMBOL;
		content = AddReceiptsToolBar(receipts_type, "");
		$("#toolbar").append(content);
		GetDetailTable();
		getPageMaxAndMin();
		$(document).ready(function(){
			if(currPage != undefined) {
			console.log(currPage);
			loadRemote();
		}
		});
		

		function getPageMaxAndMin() {
			var _url = RemoteLinkAddress + "/logistics/deliverorder/getmaxminid.do";
			$.ajax({ //调用ajax方法，从服务器获取到该订单的所有数据
				type: "get",
				url: _url,
				dataType: "json", //服务器返回的数据类型
				success: function(result) {
					console.log(result);
					if(result != null) {
						MaxPage = result.MAXID;
						MinPage = result.MINID;
						currPage = result.MINID + 1;
					}
				}, //请求成功后，接受服务器传来的Json字符串，并做相应的处理
				error: function(xhr, status, error) {
					$.messager.alert("错误", "请求失败!");
				}
			});
		}

		///单据相关功能
		function frontpage() { //上一张
			if(currPage > MinPage) {
				var _url = RemoteLinkAddress + '/logistics/deliverorder/pre.do?ID=' + currPage;
				getRemoteData(_url);
			} else {
				$.messager.alert("提示", "没有上张");
			}
		}

		function nextpage() { //下一张
			if(currPage < MaxPage) {
				var _url = RemoteLinkAddress + '/logistics/deliverorder/next.do?ID=' + currPage;
				getRemoteData(_url);
			} else {
				$.messager.alert(" 提示", "没有下张");
			}
		}

		function searchmore() {
			AddTabIn("配送单查询", parent.$('#tabs'), "UI/Logistics/DeliverManagementOrder/DeliverManagementOrderSearch.html");
		}

		function print() {
			if(isVerify == 0) {
				$.messager.alert("警告", "订单未审核，不能打印");
				return;
			}
			var pLocation = "";
			if(currPage == AddFlag) {
				$.messager.alert("错误", "当前页面为新增页面不能打印");
				return;
			} else {
				pLocation = "DeliverManagementOrderPrint.html?id=" + currPage;
				window.open(pLocation);
			}
		}

		function save() {
			if(isVerify == 1) {
				$.messager.alert("警告", "订单已审核，不能保存");
				return;
			}
			getData();
		}

		function loadRemote() {
			var _url = RemoteLinkAddress + '/logistics/deliverorder/findbyid.do?ID=' + currPage;
			getRemoteData(_url);
		}

		function GetDetailTable() { //构造datagrid中的数据
			$('#tt').datagrid({
				height: 350,
				toolbar: '#toolbar2',
				rownumbers: 'true',
				autoRowHeight: 'true',
				fitColumns: 'false',
				columns: [
					[{
						field: 'ID',
						title: '销售单编号',
						width: '22%',
						align: 'center'
					}, {
						field: 'CUSTOMER_TYPE',
						title: '用户组',
						width: '22%',
						align: 'center'
					}, {
						field: 'CUSTOMER_NAME',
						title: '配送单位',
						width: '30%',
						align: 'center'
					}, {
						field: 'DISTRIBUTION_DATE',
						title: '配送时间',
						width: '17%',
						align: 'center'
					}]
				]
			});
		}

		function getData() {
			var _data = submitFormData();
			_data.LUMP_SUM = CalDeliverCost(_data);
			$("#input_LUMP_SUM").textbox('setValue', _data.LUMP_SUM);
			for(s in _data) {
				updateData[s] = _data[s];
			}
			submitData(updateData);
		}

		function submitData(_data) {
			var _senddata = JSON.stringify(_data);
			$.ajax({
				dataType: 'JSON',
				url: RemoteLinkAddress + "/logistics/deliverorder/update.do",
				data: 'a=' + _senddata,
				type: "POST",
				success: function(result) {
					$.messager.alert("提示信息", "保存成功");
				},
				error: function(result) {
					alert('error' + JSON.stringify(result));
				}
			});
		}

		function getRemoteData(_url) //统一获取远程的数据
		{
			$.ajax({ //调用ajax方法，从服务器获取到该订单的所有数据
				type: "get",
				url: _url,
				dataType: "json", //服务器返回的数据类型
				success: function(result) {
					console.log(result);
					if(result != null) {
						getFormData(result);
						isVerify = result.ISVERIFY;
						verifyStatus(isVerify, true);
						currPage = result.ID; //表示传回的ID
						currid = result.ID;
						updateData = result;
						var _data = result.rows; //将获取到的数据中字头为rows的数据赋值给_data
						$('#tt').datagrid('loadData', _data); //调用easyui的loadData方法，将数据写入id为tt的datagrid中
					}
				}, //请求成功后，接受服务器传来的Json字符串，并做相应的处理
				error: function(xhr, status, error) {
					$.messager.alert("错误", "请求失败!");
				}
			});
		}

		function deletedata() {
			if(isVerify == 1) {
				$.messager.alert("警告", "订单已审核，不能删除");
				return;
			}
			$.messager.confirm('Confirm', '是否删除', function(r) {
				if(r) {
					$.post(RemoteLinkAddress + "/logistics/deliverorder/delete.do", {
							ID:currPage 
						},
						function(result) {
							if(result.msg == "success") {
								$('#tt').datagrid('reload'); // reload the user data
								$.messager.alert({ // show success message
									title: '成功',
									msg: '删除成功'
								});
								nextpage();
							} else {
								$.messager.alert({ // show error message
									title: 'Error',
									msg: result.msg
								});
							}
						},
						'json');
				}
			});
		}

		function verifydata() {
			if(isVerify == 1) {
				$.messager.alert("警告", "订单已审核，无须再审");
				return;
			}
			$.messager.confirm("确认", "是否审核", function(r) {
				if(r) {
					$.post(RemoteLinkAddress + "/logistics/deliverorder/verify.do", {
						"ID": updateData.ID,
					}, function(result) {
						if(result.msg == "success") {
							$.messager.alert({ // show error message
								title: '成功',
								msg: '审核成功!'
							});
							verifyStatus(1, true);
							isVerify = 1;
						} else {
							$.messager.alert({ // show error message
								title: 'Error',
								msg: result.msg
							});
						}
					}, 'json');
				}
			});
		}

		function unverifydata() {
			if(isVerify == 0) {
				$.messager.alert("警告", "订单已弃审，无须再审");
				return;
			}
			$.messager.confirm('Confirm', '是否弃审', function(r) {
				if(r) {
					$.post(RemoteLinkAddress + "/logistics/deliverorder/unverify.do", {
							"ID": updateData.ID,
						},
						function(result) {
							if(result.msg == "success") {
								$.messager.alert({
									title: '成功',
									msg: '放弃审核成功!'
								});
								verifyStatus(0, true);
								isVerify = 0;
							} else {
								$.messager.alert({
									title: 'Error',
									msg: result.msg
								});
							}
						},
						'json');
				}
			});
		}
		
		function exportExcel() {
			if(currid === AddFlag) {
				$.messager.alert("警告", "该订单为新增订单，无法导出Excel！");
				return;
			}
			$.messager.confirm("提示", "确认导出Excel表格吗？", function(r) {
				if(r) {
					$.ajax({ //调用ajax方法，从服务器获取到该订单的所有数据
						type: "get",
						dataType: "json", //服务器返回的数据类型
						url: RemoteLinkAddress + "/logistics/deliverorder/excelorder.do",
						data: {
							"ID": currid
						},
						success: function(result) {
							window.location.href = result.path;
						}, //请求成功后，接受服务器传来的Json字符串，并做相应的处理
						error: function(xhr, status, error) {
							$.messager.alert("错误", "请求失败!");
						}
					});
				}
			});
		}
	</script>

</html>